﻿using Enterprise_Set.API.Application.Commands.Week1.BusinessEntities;
using Enterprise_Set.API.Application.Commands.Week1.Warehouse_CRUD;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using THE_WIND_RISES.Common.Domans.BasicInformation.Departments;

namespace Enterprise_Set.API.Controllers.Week1
{
    /// <summary>
    /// 第一周基础信息添加
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class BasicController : ControllerBase
    {
        /// <summary>
        /// 中介者
        /// </summary>
        public IMediator mediator { get; set; }
        /// <summary>
        /// 日志
        /// </summary>
        private readonly ILogger<BasicController> logger;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="mediator"></param>
        /// <param name="logger"></param>
        public BasicController(IMediator mediator, ILogger<BasicController> logger)
        {
            this.mediator = mediator;
            this.logger = logger;
        }

        /// <summary>
        /// 部门添加
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<THE_WIND_RISES.Common.Dtos.Result> AddDepartment(DepartmentCreateCommand cmd)
        {
            try
            {
                logger.LogInformation("部门添加");
                return await mediator.Send(cmd);
            }
            catch (Exception ex)
            {
                logger.LogError("部门添加失败" + ex.Message);
                throw;
            }
        }
        /// <summary>
        /// 企业添加
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<THE_WIND_RISES.Common.Dtos.Result> AddEnterprise(EnterpriseCreareCommand cmd)
        {
            try
            {
                logger.LogInformation("企业添加");
                return await mediator.Send(cmd);
            }
            catch (Exception ex)
            {
                logger.LogError("企业添加失败" + ex.Message);
                throw;
            }
        }
    }
}
